Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OrderBook: Add market prices using Oracles #1674

Merged
merged 83 commits into from
Feb 2, 2024
Merged

Conversation

lemunozm
Copy link
Contributor

@lemunozm lemunozm commented Jan 5, 2024

Description

Improve pallet-order-book to swap currencies with a market price.

Change list

@lemunozm lemunozm self-assigned this Jan 5, 2024
@lemunozm
Copy link
Contributor Author

lemunozm commented Jan 5, 2024

Compiling with cargo check -p pallet-order-book

@lemunozm lemunozm requested review from mustermeiszer and removed request for mikiquantum January 5, 2024 10:18
@lemunozm lemunozm force-pushed the order-book/market-prices branch from 2e32be4 to 6b59210 Compare January 5, 2024 15:25
Copy link
Contributor Author

@lemunozm lemunozm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I already have the base logic. Looking for your (fast) feedback before getting more into details @mustermeiszer @wischli

libs/traits/src/lib.rs Outdated Show resolved Hide resolved
pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
@lemunozm lemunozm changed the title OrderBook: Add market prices OrderBook: Add market prices using Oracles Jan 5, 2024
Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments. Did not see anything I disagree with, great work!

libs/traits/src/lib.rs Outdated Show resolved Hide resolved
pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
@wischli wischli added D5-breaks-api Pull request changes public api. Document changes publicly. I8-enhancement An additional feature. labels Jan 8, 2024
@wischli wischli added this to the Centrifuge 1025 milestone Jan 8, 2024
Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to look at more depth tomorrrow, but what I can already say is that

  • We need an additional extrinsic that is callable by T::AdminOrigin and allows to set a T::FeederId

libs/traits/src/lib.rs Outdated Show resolved Hide resolved
libs/traits/src/lib.rs Outdated Show resolved Hide resolved
pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
@lemunozm
Copy link
Contributor Author

lemunozm commented Jan 10, 2024

Note: in case we need again the default inverse ratios in the future here is the reverted commit: 451a6c7

mustermeiszer
mustermeiszer previously approved these changes Jan 10, 2024
Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks!

@lemunozm lemunozm added D8-migration Pull request touches storage and needs migration code. Q7-very-hard Can be done by an expert coder with a deep knowledge of the codebase. labels Jan 12, 2024
@lemunozm
Copy link
Contributor Author

lemunozm commented Feb 1, 2024

I made a couple of modifications to the internal FI structure:

  • I've added a type Correlation to keep track of two symmetrical variables that are being correlated, forcing that they always are correlated.
  • I've split post_increase/decrease_swap() methods into two variants, one when the swap is actually a swap and another when the swap is actually a cancelation of another swap. Before that, there were a lot of concept mixed and with this explicit separation, I think the code is more easy to follow.

@lemunozm lemunozm force-pushed the order-book/market-prices branch from 9e32a92 to e2e3091 Compare February 1, 2024 14:50
Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Part 1: Order book

pallets/foreign-investments/src/entities.rs Outdated Show resolved Hide resolved
// update if the pair exists.
let _old_min_order = TradingPair::<T>::get(&asset_in, &asset_out)?;
TradingPair::<T>::insert(&asset_in, &asset_out, min_order);
MarketFeederId::<T>::put(feeder_id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An Event would be nice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that FeederId is just a value in a ValueStorage, who would want to look for the event instead of reading the storage directly?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Events are a means of saying that the state changed, so yes indexers will most likely only see that change if there was an evenrt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, because the indexer can not also index "calls" done, right? Because in that case, just seeing that the call has been performed, they now the state has changed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done anyways here: 4a0f52a

pallets/order-book/src/lib.rs Show resolved Hide resolved
pallets/order-book/src/lib.rs Outdated Show resolved Hide resolved
* minor renaming

* fix: add same currency orderbook short cut

* chore: enable test debugging for info

* fix: FI integration tests

* chore: enable debug logging

* tests: fix after rebasing

* chore: remove debug lines

* chore: proof order of operators is not the issue

* fix: swapped decrease amount

* fix: ForeignIdToSwapId removal

* tests: apply fixed ForeignIdToSwapId removal

---------

Co-authored-by: lemunozm <[email protected]>
@wischli wischli mentioned this pull request Feb 2, 2024
11 tasks
Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for all the sweat and effort you have put into this!

Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a huge one!! Thanks to both @lemunozm and @wischli for the effort and brain juice that went into this here!

@lemunozm
Copy link
Contributor Author

lemunozm commented Feb 2, 2024

Thanks both for your awesome feedback and support 🙌🏻

@lemunozm lemunozm merged commit 8cd9197 into main Feb 2, 2024
9 checks passed
@wischli wischli deleted the order-book/market-prices branch February 5, 2024 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
D5-breaks-api Pull request changes public api. Document changes publicly. D8-migration Pull request touches storage and needs migration code. I8-enhancement An additional feature. Q7-very-hard Can be done by an expert coder with a deep knowledge of the codebase.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants